


import { search_commodity } from '@/api'

const state = {
  // 搜索的数据
  search_list: [

  ]
}
const actions = {

  //发送获取搜索页面数据
  async search_commodity_gain({ commit }, searcHParams) {

    const search_page = await search_commodity(searcHParams)

    if (search_page.code === 200) {
      commit('stockpile_search_data', search_page.data)
    } else {
      console.log(search_page.message)
    }
  }

}


const mutations = {
  // 储存搜索数据
  stockpile_search_data(state, data) {
    state.search_list = data
  }
}

//计算搜索内的数据
const getters = {
  //获取品牌数据
  brand_data(state) {
    console.log(state)
    return state.search_list.trademarkList
  },

  //网络制式数据
  network_system(state) {
    return state.search_list.attrsList
  },

  //商品渲染数据
  merchandise(state) {
    return state.search_list.goodsList
  },
  //获取一共有多少页
  total(state) {
    return state.search_list.total
  }
}

export default {
  namespaced: true, //设置命名空间 用来区分不同的模块
  state,
  actions,
  mutations,
  getters
}
